package com.yaorange.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.yaorange.teaching.bo.AddTeachingPlanBo;
import com.yaorange.teaching.bo.PreviewTeachingPlanBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yaorange.common.log.annotation.Log;
import com.yaorange.common.log.enums.BusinessType;
import com.yaorange.common.security.annotation.RequiresPermissions;
import com.yaorange.teaching.domain.YaTeachingPlan;
import com.yaorange.teaching.service.IYaTeachingPlanService;
import com.yaorange.common.core.web.controller.BaseController;
import com.yaorange.common.core.web.domain.AjaxResult;
import com.yaorange.common.core.utils.poi.ExcelUtil;
import com.yaorange.common.core.web.page.TableDataInfo;

/**
 * 教学计划(课)Controller
 *
 * @author ruoyi
 * @date 2024-11-20
 */
@RestController
@RequestMapping("/teaching_plan")
public class YaTeachingPlanController extends BaseController
{
    @Autowired
    private IYaTeachingPlanService yaTeachingPlanService;

    /**
     * 查询教学计划(课)列表
     */
    @RequiresPermissions("teaching:teaching_plan:list")
    @GetMapping("/list/all")
    public TableDataInfo listall(@RequestParam("className")String className,@RequestParam("stage")Integer stage)
    {
        List<YaTeachingPlan> list = yaTeachingPlanService.selectYaTeachingPlanList(className,stage);
        return getDataTable(list);
    }


    /**
     * 查询教学计划(课)列表
     */
    @RequiresPermissions("teaching:teaching_plan:list")
    @PostMapping("/list")
    public TableDataInfo list(YaTeachingPlan yaTeachingPlan,@RequestBody List<String> classNames)
    {
        startPage();
        List<YaTeachingPlan> list = yaTeachingPlanService.selectYaTeachingPlanList(yaTeachingPlan,classNames);
        return getDataTable(list);
    }

    /**
     * 导出教学计划(课)列表
     */
    @RequiresPermissions("teaching:teaching_plan:export")
    @Log(title = "教学计划(课)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaTeachingPlan yaTeachingPlan)
    {
        List<YaTeachingPlan> list = yaTeachingPlanService.selectYaTeachingPlanList(yaTeachingPlan, null);
        ExcelUtil<YaTeachingPlan> util = new ExcelUtil<YaTeachingPlan>(YaTeachingPlan.class);
        util.exportExcel(response, list, "教学计划(课)数据");
    }

    /**
     * 获取教学计划(课)详细信息
     */
    @RequiresPermissions("teaching:teaching_plan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yaTeachingPlanService.selectYaTeachingPlanById(id));
    }

    @RequiresPermissions("teaching:teaching_plan:add")
    @Log(title = "教学计划(课)", businessType = BusinessType.INSERT)
    @PostMapping("/workday")
    public AjaxResult addWorkday(@Valid @RequestBody PreviewTeachingPlanBo previewTeachingPlanBo)
    {
        yaTeachingPlanService.addWorkday(previewTeachingPlanBo);
        return AjaxResult.success(yaTeachingPlanService.preview(previewTeachingPlanBo));
    }


    @RequiresPermissions("teaching:teaching_plan:add")
    @Log(title = "教学计划(课)", businessType = BusinessType.INSERT)
    @PostMapping("/holiday")
    public AjaxResult addHoliday(@Valid @RequestBody PreviewTeachingPlanBo previewTeachingPlanBo)
    {
        yaTeachingPlanService.addHoliday(previewTeachingPlanBo);
        return AjaxResult.success(yaTeachingPlanService.preview(previewTeachingPlanBo));
    }


    /**
     * 创建预览
     */
    @RequiresPermissions("teaching:teaching_plan:add")
    @Log(title = "教学计划(课)", businessType = BusinessType.INSERT)
    @PostMapping("/preview")
    public AjaxResult preview(@Valid @RequestBody PreviewTeachingPlanBo previewTeachingPlanBo/*, BindingResult bs*/)
    {
        return AjaxResult.success(yaTeachingPlanService.preview(previewTeachingPlanBo));
    }
    /**
     * 新增教学计划(课)
     */
    @RequiresPermissions("teaching:teaching_plan:add")
    @Log(title = "教学计划(课)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddTeachingPlanBo addTeachingPlanBo)
    {
        return toAjax(yaTeachingPlanService.insertYaTeachingPlan(addTeachingPlanBo));
    }

    /**
     * 修改教学计划(课)
     */
    @RequiresPermissions("teaching:teaching_plan:edit")
    @Log(title = "教学计划(课)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YaTeachingPlan yaTeachingPlan)
    {
        return toAjax(yaTeachingPlanService.updateYaTeachingPlan(yaTeachingPlan));
    }

    /**
     * 删除教学计划(课)
     */
    @RequiresPermissions("teaching:teaching_plan:remove")
    @Log(title = "教学计划(课)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaTeachingPlanService.deleteYaTeachingPlanByIds(ids));
    }
}
